module FragmentHelper
  def link_to_vote fragment, label, level
	link_to(label, url_for({:controller=>'fragment',:action=>'vote', :id=>fragment}),:id=>'vote_submit_link',:value=>level)
  end

  def show_merge_link (fragment, stais=vote_statistical)
    novel = fragment.novel
    return if Fragment::FRAGMENT_MERGE ==fragment.merge  # If fragment is merged, don't show merged link anymore'
    return unless novel
    return unless novel.user_id==session[:user_id]
    link = link_to "并入", {:controller=>"fragment", :action=>"merge", :id=>@fragment}
    case novel.linkrule
    when Novel::LINK_RULE_1
      link
    when  Novel::LINK_RULE_2
      link if fragment.can_be_merged
    when Novel::LINK_RULE_3
      #No need merge links. The vote will be merged auto
    end
  end

  def show_modify_link fragment
    return if Fragment::FRAGMENT_MERGE ==fragment.merge  # If fragment is merged, it can't be modifed any more.'
    link = link_to ">>修改", {:controller=>"fragment", :action=>"edit", :id=>@fragment}
    link if fragment.user and fragment.user.id == session[:user_id]
  end

  def show_detail_link fragment
      link_to ">>详细", {:controller=>"fragment", :action=>"show", :id=>@fragment}
  end
  
end
